package com.example.databasetest

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteDatabase.CursorFactory
import android.database.sqlite.SQLiteOpenHelper
import android.widget.Toast
import android.content.ContentValues




class MyDatabaseHelper(
    private val mContext: Context, name: String?,
    factory: CursorFactory?, version: Int
) :
    SQLiteOpenHelper(mContext, name, factory, version) {
    override fun onCreate(db: SQLiteDatabase) {
        db.execSQL(CREATE)
        //Toast.makeText(mContext, "Create succeeded", Toast.LENGTH_SHORT).show()
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
    // TODO 创建数据库后，对数据库的操作
    // sql中Constant是用来存放一些关于数据库的常量的类
    // 类型有：Integer、text文本、varchar(n)、real浮点型、blob二进制类型
    companion object {
        const val CREATE =  "create table temp(_id integer primary key autoincrement,Home text,Date text,time text,temperatures real,hum real)"
    }


    fun deleteDatabase(context: Context, databaseName: String?): Boolean {
        return context.deleteDatabase(databaseName)
    }
}